package com.ssy.lingxi.marketing.controller.mobile;

import cn.hutool.core.collection.CollectionUtil;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.api.model.request.ActivityGoodsQuantityCheckRequest;
import com.ssy.lingxi.marketing.api.model.request.CartActivityPriceRequest;
import com.ssy.lingxi.marketing.model.vo.activity.response.CartActivityPriceResponse;
import com.ssy.lingxi.marketing.model.vo.coupon.request.MobileActivityGoodsPageReq;
import com.ssy.lingxi.marketing.model.vo.coupon.request.MobileGoodsRelationTagReq;
import com.ssy.lingxi.marketing.model.vo.coupon.request.MobileProductDetailTagReq;
import com.ssy.lingxi.marketing.model.vo.coupon.response.MobileActivityGoodsPageResp;
import com.ssy.lingxi.marketing.model.vo.coupon.response.MobileGoodsRelationTagResp;
import com.ssy.lingxi.marketing.model.vo.coupon.response.MobileProductDetailTagResp;
import com.ssy.lingxi.marketing.model.vo.coupon.response.MobileSetmealGoodsGroupResp;
import com.ssy.lingxi.marketing.service.IActivityPriceCalculateService;
import com.ssy.lingxi.marketing.service.IMobileActivityGoodsService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu App - 活动商品
 * @author yzc
 * @version 2.0.0
 * @date 2021/9/6
 */
@RestController
@RequestMapping("/marketing/mobile/activity/goods")
public class MobileActivityGoodsController extends BaseController {

    @Resource
    private IMobileActivityGoodsService mobileActivityGoodsService;
    @Resource
    private IActivityPriceCalculateService activityPriceCalculateService;

    /**
     * 查询活动sku商品详情活动标签
     **/
    @RequestMapping(value = "/detail/tag", method = RequestMethod.POST)
    public Wrapper<MobileProductDetailTagResp> getActivityGoodsProductDetailTag(@Valid @RequestBody MobileProductDetailTagReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.getActivityGoodsProductDetailTag(loginUser, request);
    }

    /**
     * 查询sku商品所关联的活动商品及活动信息
     **/
    @RequestMapping(value = "/relation/tag", method = RequestMethod.POST)
    public Wrapper<MobileGoodsRelationTagResp> getActivityRelationGoods(@Valid @RequestBody MobileGoodsRelationTagReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.getActivityRelationGoods(loginUser, request);
    }

    /**
     * 查询sku商品所关联的活动商品及活动信息-新
     **/
    @RequestMapping(value = "/relation/goods/list", method = RequestMethod.POST)
    public Wrapper<MobileGoodsRelationTagResp> getActivityRelationGoodsList(@Valid @RequestBody MobileGoodsRelationTagReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.getActivityRelationGoodsList(loginUser, request);
    }

    /**
     * 活动商品分页列表
     **/
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<MobileActivityGoodsPageResp>> pageActivityGoods(@Valid MobileActivityGoodsPageReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.pageActivityGoods(loginUser, request);
    }

    /**
     * 计算购物车商品活动价
     **/
    @RequestMapping(value = "/price/calculate", method = RequestMethod.POST)
    public Wrapper<List<CartActivityPriceResponse>> priceCalculate(@Valid @RequestBody List<CartActivityPriceRequest> request) {
        if (CollectionUtil.isEmpty(request)) {
            return Wrapper.success();
        }
        //request.forEach(o ->ValidatorUtil.validate(o));
        return activityPriceCalculateService.calculateActivityPrice(getSysUser(), request);
    }

    /**
     * 校验购买数量【加入购物车的商品】
     **/
    @RequestMapping(value = "/check/quantity", method = RequestMethod.POST)
    public Wrapper<Double> checkQuantity(@Valid @RequestBody ActivityGoodsQuantityCheckRequest request) {
        return activityPriceCalculateService.checkQuantityByAddCart(getSysUser(), request);
    }


    /**
     * 查询套餐图列表（商品详情页）
     **/
    @RequestMapping(value = "/setmeal/img/list", method = RequestMethod.POST)
    public Wrapper<List<MobileSetmealGoodsGroupResp>> getSetmealImgList(@Valid @RequestBody MobileGoodsRelationTagReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.getSetmealImgList(loginUser, request);
    }

    /**
     * 查询套餐列表
     **/
    @RequestMapping(value = "/setmeal/list", method = RequestMethod.POST)
    public Wrapper<List<MobileSetmealGoodsGroupResp>> getSetmealList(@Valid @RequestBody MobileGoodsRelationTagReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.getSetmealList(loginUser, request);
    }

    /**
     * 查询套餐子商品列表[暂废弃]

    @RequestMapping(value = "/setmeal/sub/goods/list", method = RequestMethod.GET)
    public Wrapper<List<MobileSetmealSubGoodsResp>> getSetmealSubGoodsList(@Valid MobileSetmealGoodsReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileActivityGoodsService.getSetmealSubGoodsList(loginUser, request);
    }
     **/
}
